package cn.softwin.controller.visittime;

import cn.softwin.pojo.SaleVisit;
import cn.softwin.service.impl.VisitTimeImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/AddVisitServlet")
public class AddVisitServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");//客户端往服务端传输
        SaleVisit visitTimes = new SaleVisit();

        String visitCustId = request.getParameter("visitCustId");
        visitTimes.setVisitId(visitCustId);

        String visitUserId=request.getParameter("visitUserId");
        visitTimes.setVisitUserId(visitUserId);

        String visitTime=request.getParameter("visitTime");
        visitTimes.setVisitTime(visitTime);

        String visitInterviewee=request.getParameter("visitInterviewee");
        visitTimes.setVisitInterviewee(visitInterviewee);

        String visitAddr = request.getParameter("visitAddr");
        visitTimes.setVisitAddr(visitAddr);

        String visitDetail = request.getParameter("visitDetail");
        visitTimes.setVisitDetail(visitDetail);

        String visitNextTime = request.getParameter("visitNextTime");
        visitTimes.setVisitNextTime(visitNextTime);

        System.out.println();
        //提交到数据库
        VisitTimeImpl visitTime1 = new VisitTimeImpl();
        boolean flag1 = visitTime1.addVisitTime(visitTimes);
        System.out.println(flag1);
        if(flag1) {
            System.out.println("添加成功");
            request.getRequestDispatcher("success.jsp").forward(request, response);
        }else {
            System.out.println("失败");
        }

    }
}
